<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div class="search" v-show="showSearch">
        <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="100px">
          <el-form-item label="卡号" prop="cardNum">
            <el-input v-model="queryParams.cardNum" placeholder="请输入卡号" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="账单还款时间" style="width: 320px;">
            <el-date-picker v-model="dateRange" value-format="YYYY-MM-DD" type="daterange" :default-value="defaultValue"
                            range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </transition>

    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5" v-if="queryParams.monthRecordId > 0">
            <el-button type="info" @click="back()" icon="Back">返回</el-button>
          </el-col>
          <el-col :span="1.5" v-if="queryParams.monthRecordId > 0">
            <el-button type="primary" icon="Plus" @click="handleAdd" v-hasPermi="['credit:outRecord:add']">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['credit:outRecord:edit']">修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['credit:outRecord:remove']">删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="warning" icon="Download" @click="handleExport" v-hasPermi="['credit:outRecord:export']">导出</el-button>
          </el-col>
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"/>
        </el-row>
      </template>

      <el-table v-loading="loading" :data="outRecordList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="账单编号" align="center" prop="recordNo" width="180"/>
        <el-table-column label="操作月份" align="center" prop="monthDate" />
        <el-table-column label="卡号" align="center" prop="cardNum" width="150"/>
        <el-table-column label="记录类型" align="center" prop="recordType" width="130">
          <template #default="scope">
<!--            <span v-if="scope.row.recordType == 0">系统自动拆分</span>-->
<!--            <span v-else-if="scope.row.recordType == 1">手动添加</span>-->
            <el-tag type="primary" v-if="scope.row.recordType == 0" effect="dark">系统自动拆分</el-tag>
            <el-tag type="success" v-else-if="scope.row.recordType == 1" effect="dark">手动添加</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="记录状态" align="center" prop="state" width="150">
          <template #default="scope">
            <!--0 - 待处理（wei）  1 - 本次已刷款   2 - 已超时未刷款-->
            <dict-tag :options="out_record_state" :value="scope.row.state" />
          </template>
        </el-table-column>
        <el-table-column label="绑定手机号" align="center" prop="phoneNum" width="120"/>
        <el-table-column label="持卡人姓名" align="center" prop="holderName" width="120"/>
        <el-table-column label="当前需刷金额" align="center" prop="billMoney" width="120">
          <template #default="scope">
            {{scope.row.billMoney}}元
          </template>
        </el-table-column>
        <el-table-column label="已刷卡金额" align="center" prop="payMoney" width="120">
          <template #default="scope">
            {{scope.row.payMoney}}元
          </template>
        </el-table-column>
        <el-table-column label="账单浮动金额" align="center" prop="floatAmount" width="120">
          <template #default="scope">
            <div v-if="scope.row.floatAmount < 0" style="color:red;">{{scope.row.floatAmount}}元</div>
            <div v-else-if="scope.row.floatAmount == 0">{{scope.row.floatAmount}}元</div>
            <div v-else-if="scope.row.floatAmount > 0" style="color:blue;">{{scope.row.floatAmount}}元</div>
          </template>
        </el-table-column>
        <el-table-column label="执行费率" align="center" prop="payRate">
          <template #default="scope">
            {{scope.row.payRate}}%
          </template>
        </el-table-column>
        <el-table-column label="刷卡手续费" align="center" prop="payFee" width="120">
          <template #default="scope">
            {{scope.row.payFee}}元
          </template>
        </el-table-column>
        <el-table-column label="出账类型" align="center" prop="isQrPay" width="120">
          <template #default="scope">
            <span v-if="scope.row.isQrPay == 0">POS刷卡</span>
            <span v-else-if="scope.row.isQrPay == 1">扫码</span>
          </template>
        </el-table-column>
        <el-table-column label="本账单还款时间" align="center" prop="billOutDay" width="160"/>
        <el-table-column label="最后还款日" align="center" prop="repayDay" width="160"/>
        <el-table-column label="打款支付时间" align="center" prop="payTime" width="160"/>
        <el-table-column label="操作人" align="center" prop="opSysUserId" />
        <el-table-column label="备注信息" align="center" prop="remark" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="120">
          <template #default="scope">
            <el-tooltip content="修改" placement="top">
              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['credit:outRecord:edit']"></el-button>
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['credit:outRecord:remove']"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total"
                  v-model:page="queryParams.pageNum"
                  v-model:limit="queryParams.pageSize"
                  @pagination="getList"/>
    </el-card>

    <!-- 添加或修改刷卡账单记录对话框 -->
    <el-dialog :title="dialogAdd.title" v-model="dialogAdd.visible" width="700px" append-to-body>
      <el-form ref="outRecordFormRef" :model="form" :rules="rules" label-width="130px">
        <el-row>
          <el-col :span="12">
            <el-col :span="24">
              <el-form-item label="操作月份" prop="monthDate">
                <el-input v-model="form.monthDate" placeholder="请输入操作月份" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="记录类型" prop="recordType">
                <el-select v-model="form.recordType" placeholder="请选择记录类型" clearable style="width:100%;">
                  <el-option :key="1" label="手动添加" :value="1" />
<!--                  <el-option :key="0" label="系统生成" :value="0" />-->
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="出款类型" prop="isQrPay">
                <el-select v-model="form.isQrPay" placeholder="请选择出款类型" clearable style="width:100%;" @change="changeIsQrPay">
                  <el-option :key="0" label="POS刷卡" :value="0" />
                  <el-option :key="1" label="扫码" :value="1" />
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="卡号" prop="cardNum">
                <el-input v-model="form.cardNum" placeholder="请输入卡号" readonly/>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="持卡人手机号" prop="phoneNum">
                <el-input v-model="form.phoneNum" placeholder="请输入绑定手机号" readonly/>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="本账单出款日期" prop="billOutDay">
                <el-date-picker clearable v-model="form.billOutDay" type="datetime"
                                value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择打款支付时间">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="是否同步生成进账" prop="isAddInRecord">
                <el-radio-group v-model="form.isAddInRecord">
                  <el-radio v-for="dict in module_yes_no" :key="parseInt(dict.value)" :label="parseInt(dict.value)">
                    {{dict.label }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-if="form.isAddInRecord == 1">
              <el-form-item label="本账单进账日期" prop="billRepayDay" >
                <el-date-picker clearable v-model="form.billRepayDay" type="datetime"
                                value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择本账单进账日期">
                </el-date-picker>
              </el-form-item>
            </el-col>

          </el-col>
          <el-col :span="12">
<!--            <el-col :span="24">-->
<!--              <el-form-item label="当前需刷金额" prop="billMoney">-->
<!--                <el-input v-model="form.billMoney" placeholder="请输入当前需刷金额">-->
<!--                  <template #append>元</template>-->
<!--                </el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
            <el-col :span="24">
              <el-form-item label="当前出账金额" prop="payMoney">
                <el-input v-model="form.payMoney" placeholder="请输入已刷卡金额" @blur="changePayFee(1)">
                  <template #append>元</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="刷卡利率" prop="payRate">
                <el-input v-model="form.payRate" placeholder="请输入刷卡利率" readonly>
                  <template #append>%</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="刷卡手续费" prop="payFee">
                <el-input v-model="form.payFee" placeholder="请输入刷卡手续费" readonly>
                  <template #append>元</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="记录状态" prop="state">
                <el-select v-model="form.state" placeholder="请选择记录状态" filterable clearable style="width: 100%;">
                  <el-option v-for="item in out_record_state"
                             :key="parseInt(item.value)" :label="item.label"
                             :value="parseInt(item.value)"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注信息" prop="remark">
                <el-input v-model="form.remark" type="textarea" placeholder="请输入备注信息" />
              </el-form-item>
            </el-col>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitForm">确认已出账</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>


    <!-- 添加或修改刷卡账单记录对话框 -->
    <el-dialog :title="dialog.title" v-model="dialog.visible" width="700px" append-to-body>
      <el-form ref="outRecordFormRef" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-col :span="24">
              <el-form-item label="操作月份" prop="monthDate">
                <el-input v-model="form.monthDate" placeholder="请输入操作月份" readonly/>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="卡号" prop="cardNum">
                <el-input v-model="form.cardNum" placeholder="请输入卡号" readonly/>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="持卡人姓名" prop="holderName">
                <el-input v-model="form.holderName" placeholder="请输入持卡人姓名" readonly/>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="持卡人手机号" prop="phoneNum">
                <el-input v-model="form.phoneNum" placeholder="请输入绑定手机号" readonly/>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="本账单出款日期" prop="billOutDay">
                <el-input v-model="form.billOutDay" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="还款日" prop="repayDay">
                <el-input v-model="form.repayDay" placeholder="请输入还款日" readonly/>
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-col :span="24">
              <el-form-item label="当前需刷金额" prop="billMoney">
                <el-input v-model="form.billMoney" placeholder="请输入当前需刷金额">
                  <template #append>元</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="刷卡利率" prop="payRate">
                <el-input v-model="form.payRate" placeholder="请输入刷卡利率" readonly>
                  <template #append>%</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="刷卡手续费" prop="payFee">
                <el-input v-model="form.payFee" placeholder="请输入刷卡手续费" readonly>
                  <template #append>元</template>
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="实际刷卡金额" prop="payMoney">
                <el-input v-model="form.payMoney" placeholder="请输入已刷卡金额" @blur="changePayFee(0)">
                  <template #append>元</template>
                </el-input>
              </el-form-item>
            </el-col>
<!--            <el-col :span="24">-->
<!--              <el-form-item label="打款支付时间" prop="payTime">-->
<!--                <el-date-picker clearable v-model="form.payTime" type="datetime"-->
<!--                                value-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择打款支付时间">-->
<!--                </el-date-picker>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
            <el-col :span="24">
              <el-form-item label="记录状态" prop="state">
                <el-select v-model="form.state" placeholder="请选择记录状态" filterable clearable style="width: 100%;">
                  <el-option v-for="item in out_record_state"
                             :key="parseInt(item.value)" :label="item.label"
                             :value="parseInt(item.value)"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注信息" prop="remark">
                <el-input v-model="form.remark" type="textarea" placeholder="请输入备注信息" />
              </el-form-item>
            </el-col>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitForm">确认已出账</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>



  </div>
</template>

<script setup name="OutRecord" lang="ts">
import { listOutRecord, getOutRecord, delOutRecord, addOutRecord, updateOutRecord } from '@/api/credit/outRecord';
import { OutRecordVO, OutRecordQuery, OutRecordForm } from '@/api/credit/outRecord/types';
import { getCard } from "@/api/credit/card";

//新页面接收参数js
import { useRoute } from "vue-router"
import {getBillMonthRecord} from "@/api/credit/bill/record";
//注意是useRoute
const route = useRoute()

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { module_state } = toRefs<any>(proxy?.useDict('module_state'));
const { out_record_state } = toRefs<any>(proxy?.useDict('out_record_state'));
const { module_yes_no } = toRefs<any>(proxy?.useDict('module_yes_no'));



const outRecordList = ref<OutRecordVO[]>([]);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);


const posRate = ref(0);
const qrRate = ref(0);



const dateRange = ref<[DateModelType, DateModelType]>(['', '']);
const defaultValue = ref<[DateModelType, DateModelType]>([
  new Date(),
  new Date(),
])
const queryFormRef = ref<ElFormInstance>();
const outRecordFormRef = ref<ElFormInstance>();



const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

const dialogAdd = reactive<DialogOption>({
  visible: false,
  title: ''
});

const initFormData: OutRecordForm = {
  id: undefined,
  /**
   *  账单编号
   */
  recordNo: undefined,
  monthRecordId:undefined,
  monthDate: undefined,
  cardId: undefined,
  cardNum: undefined,
  recordType: undefined,
  phoneNum: undefined,
  holderName: undefined,
  holderId: undefined,
  billMoney: undefined,
  payMoney: undefined,
  payRate: undefined,
  payFee: undefined,
  /**
   * 管理费率
   */
  manageRate: undefined,
  /**
   *  本笔管理费
   */
  manageFee: undefined,
  /**
   * 本笔产生的利润：
   */
  profit: undefined,

  isQrPay: undefined,
  state: undefined,
  repayDay: undefined,
  billOutDay:undefined,
  isDanger: undefined,
  payTime: undefined,
  opSysUserId: undefined,
  remark: undefined,
  isDel: undefined,
  billRepayDay:undefined,
  creditCard: undefined,
  billMonthRecord: undefined,
  isAddInRecord:undefined,
}
const data = reactive<PageData<OutRecordForm, OutRecordQuery>>({
  form: {...initFormData},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    monthRecordId:undefined,
    monthDate: undefined,
    cardId: undefined,
    cardNum: undefined,
    recordType: undefined,
    phoneNum: undefined,
    holderName: undefined,
    holderId: undefined,
    billMoney: undefined,
    payMoney: undefined,
    payRate: undefined,
    payFee: undefined,
    isQrPay: undefined,
    state: undefined,
    repayDay: undefined,
    isDanger: undefined,
    payTime: undefined,
    opSysUserId: undefined,
    isDel: undefined,
    params: {
    }
  },
  rules: {
    id: [
      { required: true, message: "不能为空", trigger: "blur" }
    ],
    monthDate: [
      { required: true, message: "操作月份不能为空", trigger: "blur" }
    ],
    cardId: [
      { required: true, message: "卡片id不能为空", trigger: "blur" }
    ],
    cardNum: [
      { required: true, message: "卡号不能为空", trigger: "blur" }
    ],
    recordType: [
      { required: true, message: "记录类型 0 - 普通账号拆分记录 1 - 手动添加刷卡记录不能为空", trigger: "change" }
    ],
    phoneNum: [
      { required: true, message: "绑定手机号不能为空", trigger: "blur" }
    ],
    holderName: [
      { required: true, message: "持卡人姓名不能为空", trigger: "blur" }
    ],
    holderId: [
      { required: true, message: "持卡人id不能为空", trigger: "blur" }
    ],
    billMoney: [
      { required: true, message: "当前需刷金额不能为空", trigger: "blur" }
    ],
    payMoney: [
      { required: true, message: "已刷卡金额不能为空", trigger: "blur" }
    ],
    payRate: [
      { required: true, message: "刷卡利率不能为空", trigger: "blur" }
    ],
    payFee: [
      { required: true, message: "刷卡手续费不能为空", trigger: "blur" }
    ],
    isQrPay: [
      { required: true, message: "是否是扫码支付不能为空", trigger: "blur" }
    ],
    state: [
      { required: true, message: "记录状态不能为空", trigger: "blur" }
    ],
    repayDay: [
      { required: true, message: "还款日不能为空", trigger: "blur" }
    ],
    isDanger: [
      { required: true, message: "是否高风险不能为空", trigger: "blur" }
    ],
    payTime: [
      { required: true, message: "打款支付时间不能为空", trigger: "blur" }
    ],
    opSysUserId: [
      { required: true, message: "操作人id不能为空", trigger: "blur" }
    ],
    remark: [
      { required: true, message: "备注信息不能为空", trigger: "blur" }
    ],
    isDel: [
      { required: true, message: "删除标识 0 - 未删除 1 - 已删除不能为空", trigger: "blur" }
    ]
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询刷卡账单记录列表 */
const getList = async () => {
  loading.value = true;

  const today = new Date();
  const year = today.getFullYear();
  let month:number = (today.getMonth() + 1); // 月份从0开始，所以要加1
  let day:number = today.getDate() ;
  let monthStr :String  = "";
  let dayStr :String  = "";
  if(month < 10){
    monthStr = '0' + month;
  }
  if(day < 10){
    dayStr = '0' + day;
  }

  dateRange.value = [year+'-'+monthStr+'-'+dayStr,year+'-'+monthStr+'-'+dayStr];


  const res = await listOutRecord(proxy?.addDateRange(queryParams.value, dateRange.value));
  outRecordList.value = res.rows;
  total.value = res.total;
  loading.value = false;
}

/** 取消按钮 */
const cancel = () => {
  reset();
  dialog.visible = false;
  dialogAdd.visible = false;
}


/** 修改按钮操作 */
const getCardInfo = async (id: number) => {
  const res = await getCard(id);
  // Object.assign(form.value.creditCard, res.data);
  form.value.cardId = res.data.id;
  form.value.cardNum = res.data.cardNum;
  form.value.holderId = res.data.holderId;
  form.value.phoneNum = res.data.phoneNum;
  posRate.value = res.data.posRate;
  qrRate.value = res.data.qrRate;
  // if(form.value.isQrPay == 0){
  //   form.value.payRate = res.data.posRate;
  // }else if(form.value.isQrPay == 1){
  //   form.value.payRate = res.data.qrRate;
  // }
}

const changeIsQrPay = (isQrPay:number)=>{
  if(isQrPay == 0){
    form.value.payRate = posRate.value;
  }else{
    form.value.payRate = qrRate.value;
  }
}

/** 修改按钮操作 */
const getMonthRecordInfo = async (id: number) => {
  const res = await getBillMonthRecord(id);
  console.log('res.data',res.data)
  if(res.data.id!=undefined){
    form.value.monthRecordId = res.data.id;
  }
  form.value.monthDate = res.data.monthCode;

  if(res.data.creditCardId!= undefined){
    await getCardInfo(res.data.creditCardId)
  }
}


/**
 *  实际刷卡金额 填好之后 重新计算手续费
 */
const changePayFee = (type:number)=>{
  if(type == 1){
    form.value.billMoney = form.value.payMoney;
  }
  let billMoney = form.value.billMoney;
  let payRate = form.value.payRate;
  let payMoney = form.value.payMoney;

  if (payMoney != undefined && payRate != undefined) {
    let payFee = parseFloat(String(payMoney * payRate / 100));
    form.value.payFee = parseFloat(payFee.toFixed(2));
    if(billMoney!=undefined){
      form.value.floatAmount = parseFloat((billMoney - payMoney).toFixed(2));
    }
  }
}


function back() {
  if (proxy?.$route.query.noGoBack) {
    proxy.$router.push({ path: "/" });
  } else {
    proxy?.$router.go(-1);
  }
}

/** 表单重置 */
const reset = () => {
  form.value = {...initFormData};
  outRecordFormRef.value?.resetFields();
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
const resetQuery = () => {
  dateRange.value = ['', '']
  queryFormRef.value?.resetFields();
  handleQuery();
}

/** 多选框选中数据 */
const handleSelectionChange = (selection: OutRecordVO[]) => {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
const handleAdd = () => {
  reset();
  if(queryParams.value.monthRecordId!= undefined && queryParams.value.monthRecordId > 0){
    getMonthRecordInfo(queryParams.value.monthRecordId);
  }
  form.value.recordType = 1;
  dialogAdd.visible = true;
  dialogAdd.title = "添加刷卡账单记录";
}

/** 修改按钮操作 */
const handleUpdate = async (row?: OutRecordVO) => {
  reset();
  const _id = row?.id || ids.value[0]
  const res = await getOutRecord(_id);
  Object.assign(form.value, res.data);
  dialog.visible = true;
  dialog.title = "修改刷卡账单记录";
}

/** 提交按钮 */
const submitForm = () => {
  outRecordFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      buttonLoading.value = true;
      if (form.value.id) {
        await updateOutRecord(form.value).finally(() =>  buttonLoading.value = false);
      } else {
        await addOutRecord(form.value).finally(() =>  buttonLoading.value = false);
      }
      proxy?.$modal.msgSuccess("修改成功");
      dialog.visible = false;
      dialogAdd.visible = false;
      await getList();
    }
  });
}

/** 删除按钮操作 */
const handleDelete = async (row?: OutRecordVO) => {
  const _ids = row?.id || ids.value;
  await proxy?.$modal.confirm('是否确认删除刷卡账单记录编号为"' + _ids + '"的数据项？').finally(() => loading.value = false);
  await delOutRecord(_ids);
  proxy?.$modal.msgSuccess("删除成功");
  await getList();
}

/** 导出按钮操作 */
const handleExport = () => {
  proxy?.download('credit/outRecord/export', {
    ...queryParams.value
  }, `outRecord_${new Date().getTime()}.xlsx`)
}

onMounted(() => {

  console.log('接收参数 ', route.query.rId)//输出的即为接收到的参数
  if(route.query.rId != undefined){
    queryParams.value.monthRecordId = parseInt(route.query.rId as string);
    form.value.monthRecordId = parseInt(route.query.rId as string);
  }

  getList();
});
</script>
